package com.deke.home.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.deke.entity.TbLink;
import com.deke.home.service.TbLinkService;
import com.deke.home.vo.TbLinkVo;
import com.deke.home.vo.TbZoneVo;
import com.deke.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author ：ludi（206913808@qq.com）
 * @date ：Created in 2022/12/10 23:46
 * @description：
 * @modified By：
 * @version:
 */
@Api(tags = "友情链接")
@RestController
@RequestMapping("/home/link")
public class TbLinkController {

    @Autowired
    private TbLinkService tbLinkService;


    @ApiOperation(value = "分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage", value = "当前页码"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示的条数")
    })
    @PostMapping("getAllLink/{currentPage}/{pageSize}")
    public Result<IPage<TbLink>> getAllLink(@PathVariable(required = true, value = "currentPage") Integer current, @PathVariable(required = true) Integer pageSize, @RequestBody TbLinkVo tbLinkVo) {
        return tbLinkService.queryByConditionPage(current, pageSize, tbLinkVo);
    }

    @ApiOperation(value = "改变状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "linkId", value = "id"),
            @ApiImplicitParam(name = "isDisable", value = "状态")
    })
    @PostMapping("changeStatus/{linkId}/{isDisable}")
    public Result changeStatus(@PathVariable String linkId, @PathVariable Integer isDisable, TbLink tbLink) {
        return tbLinkService.changeStatus(linkId, isDisable, tbLink);
    }

    @ApiOperation(value = "删除操作")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "map", value = "id"),
    })
    @PostMapping("deleteLink")
    public Result deleteLink(@RequestBody Map map, TbLink tbLink) {
        return tbLinkService.deleteLink(map, tbLink);
    }


    @ApiOperation(value = "添加操作")
    @PostMapping("addLink")
    public Result addLink(@RequestBody TbLink tbLink){
        return tbLinkService.addLink(tbLink);
    }

}